package com.uzai.console.service.feign.impl;

import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.dto.feign.ksorder.*;
import com.uzai.console.dto.feign.ksorder.KsOrderSettledDto;
import com.uzai.console.service.feign.KsOrderFeignService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Auther: lucher
 * @Date: 2021/11/24 16:24
 * @Description:
 */
@Component
public class KsOrderFeignFallbackFactory implements FallbackFactory<KsOrderFeignService> {

    private static Logger logger = LoggerFactory.getLogger(KsOrderFeignFallbackFactory.class);

    @Override
    public KsOrderFeignService create(Throwable throwable){

        logger.error("--抖音订单微服务调用出错，err:={}", throwable);

        return  new KsOrderFeignService(){
            @Override
            public UzaiRespVo<Object> settled(KsOrderSettledDto ksOrderSettledDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unfreeze(KsOrderUnfreezeDto ksOrderUnfreezeDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unbind(KsOrderUnbindDto ksOrderUnbindDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> bind(KsOrderBindDto ksOrderBindDto) {
                UzaiRespVo<Object>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Boolean> pull(KsOrderPullDto ksOrderPullDto) {
                UzaiRespVo<Boolean>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Boolean> prvPull(KsOrderPrvPullDto ksOrderPrvPullDto) {
                UzaiRespVo<Boolean>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

        };
    }

}
